<?php


abstract class BaseBeatPeer {

	
	const DATABASE_NAME = 'propel';

	
	const TABLE_NAME = 'beat';

	
	const CLASS_DEFAULT = 'lib.model.Beat';

	
	const NUM_COLUMNS = 21;

	
	const NUM_LAZY_LOAD_COLUMNS = 0;


	
	const ID = 'beat.ID';

	
	const BEAT_NAME = 'beat.BEAT_NAME';

	
	const KARAOKE_FILE_PATH = 'beat.KARAOKE_FILE_PATH';

	
	const LYRIC_FILE_PATH = 'beat.LYRIC_FILE_PATH';

	
	const ARTIST = 'beat.ARTIST';

	
	const COMPOSER = 'beat.COMPOSER';

	
	const ALBUM = 'beat.ALBUM';

	
	const TRACK_NO = 'beat.TRACK_NO';

	
	const GENRE = 'beat.GENRE';

	
	const GENRE_ID = 'beat.GENRE_ID';

	
	const LYRICS = 'beat.LYRICS';

	
	const BITRATE = 'beat.BITRATE';

	
	const DURATION = 'beat.DURATION';

	
	const BEAT_FORMAT = 'beat.BEAT_FORMAT';

	
	const RECORD = 'beat.RECORD';

	
	const CREATED_DATETIME = 'beat.CREATED_DATETIME';

	
	const TYPE = 'beat.TYPE';

	
	const IVR_FILE_PATH = 'beat.IVR_FILE_PATH';

	
	const IVR_STATUS = 'beat.IVR_STATUS';

	
	const IS_HOT = 'beat.IS_HOT';

	
	const HIDE_STATUS = 'beat.HIDE_STATUS';

	
	private static $phpNameMap = null;


	
	private static $fieldNames = array (
		BasePeer::TYPE_PHPNAME => array ('Id', 'BeatName', 'KaraokeFilePath', 'LyricFilePath', 'Artist', 'Composer', 'Album', 'TrackNo', 'Genre', 'GenreId', 'Lyrics', 'Bitrate', 'Duration', 'BeatFormat', 'Record', 'CreatedDatetime', 'Type', 'IvrFilePath', 'IvrStatus', 'IsHot', 'HideStatus', ),
		BasePeer::TYPE_COLNAME => array (BeatPeer::ID, BeatPeer::BEAT_NAME, BeatPeer::KARAOKE_FILE_PATH, BeatPeer::LYRIC_FILE_PATH, BeatPeer::ARTIST, BeatPeer::COMPOSER, BeatPeer::ALBUM, BeatPeer::TRACK_NO, BeatPeer::GENRE, BeatPeer::GENRE_ID, BeatPeer::LYRICS, BeatPeer::BITRATE, BeatPeer::DURATION, BeatPeer::BEAT_FORMAT, BeatPeer::RECORD, BeatPeer::CREATED_DATETIME, BeatPeer::TYPE, BeatPeer::IVR_FILE_PATH, BeatPeer::IVR_STATUS, BeatPeer::IS_HOT, BeatPeer::HIDE_STATUS, ),
		BasePeer::TYPE_FIELDNAME => array ('id', 'beat_name', 'karaoke_file_path', 'lyric_file_path', 'artist', 'composer', 'album', 'track_no', 'genre', 'genre_id', 'lyrics', 'bitrate', 'duration', 'beat_format', 'record', 'created_datetime', 'type', 'ivr_file_path', 'ivr_status', 'is_hot', 'hide_status', ),
		BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, )
	);

	
	private static $fieldKeys = array (
		BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'BeatName' => 1, 'KaraokeFilePath' => 2, 'LyricFilePath' => 3, 'Artist' => 4, 'Composer' => 5, 'Album' => 6, 'TrackNo' => 7, 'Genre' => 8, 'GenreId' => 9, 'Lyrics' => 10, 'Bitrate' => 11, 'Duration' => 12, 'BeatFormat' => 13, 'Record' => 14, 'CreatedDatetime' => 15, 'Type' => 16, 'IvrFilePath' => 17, 'IvrStatus' => 18, 'IsHot' => 19, 'HideStatus' => 20, ),
		BasePeer::TYPE_COLNAME => array (BeatPeer::ID => 0, BeatPeer::BEAT_NAME => 1, BeatPeer::KARAOKE_FILE_PATH => 2, BeatPeer::LYRIC_FILE_PATH => 3, BeatPeer::ARTIST => 4, BeatPeer::COMPOSER => 5, BeatPeer::ALBUM => 6, BeatPeer::TRACK_NO => 7, BeatPeer::GENRE => 8, BeatPeer::GENRE_ID => 9, BeatPeer::LYRICS => 10, BeatPeer::BITRATE => 11, BeatPeer::DURATION => 12, BeatPeer::BEAT_FORMAT => 13, BeatPeer::RECORD => 14, BeatPeer::CREATED_DATETIME => 15, BeatPeer::TYPE => 16, BeatPeer::IVR_FILE_PATH => 17, BeatPeer::IVR_STATUS => 18, BeatPeer::IS_HOT => 19, BeatPeer::HIDE_STATUS => 20, ),
		BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'beat_name' => 1, 'karaoke_file_path' => 2, 'lyric_file_path' => 3, 'artist' => 4, 'composer' => 5, 'album' => 6, 'track_no' => 7, 'genre' => 8, 'genre_id' => 9, 'lyrics' => 10, 'bitrate' => 11, 'duration' => 12, 'beat_format' => 13, 'record' => 14, 'created_datetime' => 15, 'type' => 16, 'ivr_file_path' => 17, 'ivr_status' => 18, 'is_hot' => 19, 'hide_status' => 20, ),
		BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, )
	);

	
	public static function getMapBuilder()
	{
		include_once 'lib/model/map/BeatMapBuilder.php';
		return BasePeer::getMapBuilder('lib.model.map.BeatMapBuilder');
	}
	
	public static function getPhpNameMap()
	{
		if (self::$phpNameMap === null) {
			$map = BeatPeer::getTableMap();
			$columns = $map->getColumns();
			$nameMap = array();
			foreach ($columns as $column) {
				$nameMap[$column->getPhpName()] = $column->getColumnName();
			}
			self::$phpNameMap = $nameMap;
		}
		return self::$phpNameMap;
	}
	
	static public function translateFieldName($name, $fromType, $toType)
	{
		$toNames = self::getFieldNames($toType);
		$key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
		if ($key === null) {
			throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
		}
		return $toNames[$key];
	}

	

	static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
	{
		if (!array_key_exists($type, self::$fieldNames)) {
			throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.');
		}
		return self::$fieldNames[$type];
	}

	
	public static function alias($alias, $column)
	{
		return str_replace(BeatPeer::TABLE_NAME.'.', $alias.'.', $column);
	}

	
	public static function addSelectColumns(Criteria $criteria)
	{

		$criteria->addSelectColumn(BeatPeer::ID);

		$criteria->addSelectColumn(BeatPeer::BEAT_NAME);

		$criteria->addSelectColumn(BeatPeer::KARAOKE_FILE_PATH);

		$criteria->addSelectColumn(BeatPeer::LYRIC_FILE_PATH);

		$criteria->addSelectColumn(BeatPeer::ARTIST);

		$criteria->addSelectColumn(BeatPeer::COMPOSER);

		$criteria->addSelectColumn(BeatPeer::ALBUM);

		$criteria->addSelectColumn(BeatPeer::TRACK_NO);

		$criteria->addSelectColumn(BeatPeer::GENRE);

		$criteria->addSelectColumn(BeatPeer::GENRE_ID);

		$criteria->addSelectColumn(BeatPeer::LYRICS);

		$criteria->addSelectColumn(BeatPeer::BITRATE);

		$criteria->addSelectColumn(BeatPeer::DURATION);

		$criteria->addSelectColumn(BeatPeer::BEAT_FORMAT);

		$criteria->addSelectColumn(BeatPeer::RECORD);

		$criteria->addSelectColumn(BeatPeer::CREATED_DATETIME);

		$criteria->addSelectColumn(BeatPeer::TYPE);

		$criteria->addSelectColumn(BeatPeer::IVR_FILE_PATH);

		$criteria->addSelectColumn(BeatPeer::IVR_STATUS);

		$criteria->addSelectColumn(BeatPeer::IS_HOT);

		$criteria->addSelectColumn(BeatPeer::HIDE_STATUS);

	}

	const COUNT = 'COUNT(beat.ID)';
	const COUNT_DISTINCT = 'COUNT(DISTINCT beat.ID)';

	
	public static function doCount(Criteria $criteria, $distinct = false, $con = null)
	{
				$criteria = clone $criteria;

				$criteria->clearSelectColumns()->clearOrderByColumns();
		if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
			$criteria->addSelectColumn(BeatPeer::COUNT_DISTINCT);
		} else {
			$criteria->addSelectColumn(BeatPeer::COUNT);
		}

				foreach($criteria->getGroupByColumns() as $column)
		{
			$criteria->addSelectColumn($column);
		}

		$rs = BeatPeer::doSelectRS($criteria, $con);
		if ($rs->next()) {
			return $rs->getInt(1);
		} else {
						return 0;
		}
	}
	
	public static function doSelectOne(Criteria $criteria, $con = null)
	{
		$critcopy = clone $criteria;
		$critcopy->setLimit(1);
		$objects = BeatPeer::doSelect($critcopy, $con);
		if ($objects) {
			return $objects[0];
		}
		return null;
	}
	
	public static function doSelect(Criteria $criteria, $con = null)
	{
		return BeatPeer::populateObjects(BeatPeer::doSelectRS($criteria, $con));
	}
	
	public static function doSelectRS(Criteria $criteria, $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}

		if (!$criteria->getSelectColumns()) {
			$criteria = clone $criteria;
			BeatPeer::addSelectColumns($criteria);
		}

				$criteria->setDbName(self::DATABASE_NAME);

						return BasePeer::doSelect($criteria, $con);
	}
	
	public static function populateObjects(ResultSet $rs)
	{
		$results = array();
	
				$cls = BeatPeer::getOMClass();
		$cls = Propel::import($cls);
				while($rs->next()) {
		
			$obj = new $cls();
			$obj->hydrate($rs);
			$results[] = $obj;
			
		}
		return $results;
	}
	
	public static function getTableMap()
	{
		return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
	}

	
	public static function getOMClass()
	{
		return BeatPeer::CLASS_DEFAULT;
	}

	
	public static function doInsert($values, $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}

		if ($values instanceof Criteria) {
			$criteria = clone $values; 		} else {
			$criteria = $values->buildCriteria(); 		}

		$criteria->remove(BeatPeer::ID); 

				$criteria->setDbName(self::DATABASE_NAME);

		try {
									$con->begin();
			$pk = BasePeer::doInsert($criteria, $con);
			$con->commit();
		} catch(PropelException $e) {
			$con->rollback();
			throw $e;
		}

		return $pk;
	}

	
	public static function doUpdate($values, $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}

		$selectCriteria = new Criteria(self::DATABASE_NAME);

		if ($values instanceof Criteria) {
			$criteria = clone $values; 
			$comparison = $criteria->getComparison(BeatPeer::ID);
			$selectCriteria->add(BeatPeer::ID, $criteria->remove(BeatPeer::ID), $comparison);

		} else { 			$criteria = $values->buildCriteria(); 			$selectCriteria = $values->buildPkeyCriteria(); 		}

				$criteria->setDbName(self::DATABASE_NAME);

		return BasePeer::doUpdate($selectCriteria, $criteria, $con);
	}

	
	public static function doDeleteAll($con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}
		$affectedRows = 0; 		try {
									$con->begin();
			$affectedRows += BasePeer::doDeleteAll(BeatPeer::TABLE_NAME, $con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	 public static function doDelete($values, $con = null)
	 {
		if ($con === null) {
			$con = Propel::getConnection(BeatPeer::DATABASE_NAME);
		}

		if ($values instanceof Criteria) {
			$criteria = clone $values; 		} elseif ($values instanceof Beat) {

			$criteria = $values->buildPkeyCriteria();
		} else {
						$criteria = new Criteria(self::DATABASE_NAME);
			$criteria->add(BeatPeer::ID, (array) $values, Criteria::IN);
		}

				$criteria->setDbName(self::DATABASE_NAME);

		$affectedRows = 0; 
		try {
									$con->begin();
			
			$affectedRows += BasePeer::doDelete($criteria, $con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public static function doValidate(Beat $obj, $cols = null)
	{
		$columns = array();

		if ($cols) {
			$dbMap = Propel::getDatabaseMap(BeatPeer::DATABASE_NAME);
			$tableMap = $dbMap->getTable(BeatPeer::TABLE_NAME);

			if (! is_array($cols)) {
				$cols = array($cols);
			}

			foreach($cols as $colName) {
				if ($tableMap->containsColumn($colName)) {
					$get = 'get' . $tableMap->getColumn($colName)->getPhpName();
					$columns[$colName] = $obj->$get();
				}
			}
		} else {

		}

		$res =  BasePeer::doValidate(BeatPeer::DATABASE_NAME, BeatPeer::TABLE_NAME, $columns);
    if ($res !== true) {
        $request = sfContext::getInstance()->getRequest();
        foreach ($res as $failed) {
            $col = BeatPeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
            $request->setError($col, $failed->getMessage());
        }
    }

    return $res;
	}

	
	public static function retrieveByPK($pk, $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}

		$criteria = new Criteria(BeatPeer::DATABASE_NAME);

		$criteria->add(BeatPeer::ID, $pk);


		$v = BeatPeer::doSelect($criteria, $con);

		return !empty($v) > 0 ? $v[0] : null;
	}

	
	public static function retrieveByPKs($pks, $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}

		$objs = null;
		if (empty($pks)) {
			$objs = array();
		} else {
			$criteria = new Criteria();
			$criteria->add(BeatPeer::ID, $pks, Criteria::IN);
			$objs = BeatPeer::doSelect($criteria, $con);
		}
		return $objs;
	}

} 
if (Propel::isInit()) {
			try {
		BaseBeatPeer::getMapBuilder();
	} catch (Exception $e) {
		Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR);
	}
} else {
			require_once 'lib/model/map/BeatMapBuilder.php';
	Propel::registerMapBuilder('lib.model.map.BeatMapBuilder');
}
